<%--
  Created by IntelliJ IDEA.
  User: 陈敏琴
  Date: 2025/10/26
  Time: 17:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>员工信息管理系统 - 员工列表</title>
  <link rel="stylesheet" href="../css/style.css">
</head>
<body>
<header>
  <div class="logo">员工信息管理系统</div>
  <div class="user-info">
    <span>欢迎, <%= ((com.cmq.web_1.employeemanage.User) session.getAttribute("user")).getUsername() %></span>
    <a href="../logout" class="logout-btn">退出登录</a>
  </div>
</header>

<nav>
  <ul>
    <li><a href="../dashboard">仪表盘</a></li>
    <li><a href="list" class="active">员工管理</a></li>
  </ul>
</nav>

<main>
  <div class="page-title">
    <h2>员工列表</h2>
    <a href="add" class="btn add-btn">添加新员工</a>
  </div>

  <% if (request.getAttribute("message") != null) { %>
  <div class="success-message"><%= request.getAttribute("message") %></div>
  <% } %>

  <% if (request.getAttribute("error") != null) { %>
  <div class="error-message"><%= request.getAttribute("error") %></div>
  <% } %>

  <table>
    <thead>
    <tr>
      <th>ID</th>
      <th>姓名</th>
      <th>部门</th>
      <th>职位</th>
      <th>薪资</th>
      <th>入职日期</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
      java.util.List<com.cmq.web_1.employeemanage.Employee> employees =
              (java.util.List<com.cmq.web_1.employeemanage.Employee>) request.getAttribute("employees");
      if (employees != null && !employees.isEmpty()) {
        for (com.cmq.web_1.employeemanage.Employee emp : employees) {
    %>
    <tr>
      <td><%= emp.getId() %></td>
      <td><%= emp.getName() %></td>
      <td><%= emp.getDepartment() %></td>
      <td><%= emp.getPosition() %></td>
      <td><%= emp.getSalary() %></td>
      <td><%= new java.text.SimpleDateFormat("yyyy-MM-dd").format(emp.getHireDate()) %></td>
      <td>
        <a href="view?id=<%= emp.getId() %>" class="btn view-btn">查看</a>
        <a href="edit?id=<%= emp.getId() %>" class="btn edit-btn">编辑</a>
        <a href="delete?id=<%= emp.getId() %>" class="btn delete-btn"
           onclick="return confirm('确定要删除该员工吗？此操作不可恢复！')">删除</a>
      </td>
    </tr>
    <%
      }
    } else {
    %>
    <tr>
      <td colspan="7" class="no-data">暂无员工数据</td>
    </tr>
    <% } %>
    </tbody>
  </table>
</main>

<footer>
  <p>&copy; 2023 员工信息管理系统 版权所有</p>
</footer>
</body>
</html>